#define DEBUG
#include <cstdio>
#include <cassert>
#define MODS 1000000007
#define MAXLRLEN 19

using namespace std;

long long solve(unsigned long long n, int a) {
  static long long f[MAXLRLEN+1][2][10][10], g[MAXLRLEN+1][2][10][10], s[MAXLRLEN+1][2][10][10];
  static int na[MAXLRLEN+1];
  if (n==0) {
    return 0;
  }
  int len=0;
  for (unsigned long long i=1; i<=n; i=i*10, len++) {
    na[len+1] = n/i%10;
  }
#ifdef DEBUG
  if (len>18) {
    printf("GG!\n");
  }
#endif
  for (int i=0; i<=len; i++) {
    for (int j=0; j<2; j++) {
      for (int k=0; k<10; k++) {
	for (int l=0; l<10; l++) {
	  f[i][j][k][l]=g[i][j][k][l]=s[i][j][k][l]=0;
	}
      }
    }
  }
  
  f[0][1][0][0] = 1;
  for (int i=0; i<len; i++) {
    for (int j=0; j<2; j++) {
      int t = j ? na[len-i] : 9;
      for (int k=0; k<10; k++) {
	for (int l=0; l<10; l++) {
	  for (int x=0; x<=t; x++) {
	    if (x!=a) {
	      f[i+1][j&&(x==t)][(k*10+x)%a][(l+x)%a] = (f[i+1][j&&(x==t)][(k*10+x)%a][(l+x)%a]+f[i][j][k][l])%MODS;
	      g[i+1][j&&(x==t)][(k*10+x)%a][(l+x)%a] = (g[i+1][j&&(x==t)][(k*10+x)%a][(l+x)%a]+g[i][j][k][l]*10%MODS+x*f[i][j][k][l]%MODS)%MODS;
	      s[i+1][j&&(x==t)][(k*10+x)%a][(l+x)%a] = (s[i+1][j&&(x==t)][(k*10+x)%a][(l+x)%a]+s[i][j][k][l]*100%MODS+20*g[i][j][k][l]%MODS*x%MODS+f[i][j][k][l]*x%MODS*x%MODS)%MODS;
	    }
	  }
	}
      }
    }
  }

  long long ans=0;
  for (int j=0; j<2; j++) {
    for (int k=1; k<10; k++) {
      for (int l=1; l<10; l++) {
	ans = (ans+s[len][j][k][l])%MODS;
      }
    }
  }
  return ans;
}

int main() {
#ifdef DEBUG
  freopen("4239.in", "r", stdin);
  freopen("4239.out", "w", stdout);
#endif

  int t;
  scanf("%d", &t);
  for (int ti=1; ti<=t; ti++) {
    long long l, r;
    int a;
    scanf("%lld %lld %d", &l, &r, &a);
    printf("%lld\n", (solve(r, a)+MODS-solve(l-1, a))%MODS);
  }

  fcloseall();
  return 0;
}
